package javaee14.Business;

import javaee14.javaee.Student;
import javaee14.DAO.StudentDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SaleService {
    StudentDAO studentDAO;
    @Autowired
    // @Qualifier(value = "bookDaoImpl")
    public void setStudent(StudentDAO studentDAO){this.studentDAO=studentDAO;}
    public void modify(Student student){ studentDAO.modify(student);}

    @Transactional
    public void dengji(){
        List<Student> studentList = studentDAO.queryAll();
        int sum=0,number=0;
        for(Student b : studentList){
            sum+=b.getResult();
            number++;
        }
        for(Student b : studentList){
            if(b.getResult()<60)
            {b.setDengji(5);b.setJunchengji(sum/number);}
            else if (b.getResult()<70)
            {b.setDengji(4);b.setJunchengji(sum/number);}
            else if (b.getResult()<80)
            {b.setDengji(3);b.setJunchengji(sum/number);}
            else if (b.getResult()<90)
            {b.setDengji(2);b.setJunchengji(sum/number);}
            else if (b.getResult()<=100)
            {b.setDengji(1);b.setJunchengji(sum/number);}
            studentDAO.modify(b);
        }
    }
}